package com.cqut.controller;


import com.cqut.VO.result.ResultVO;
import com.cqut.entity.CourseMaterial;
import com.cqut.mapper.CourseMaterialMapper;
import com.cqut.service.CourseMaterialService;
import com.cqut.util.ResultVOUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import org.springframework.stereotype.Controller;

import java.util.List;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author 冯永龙
 * @since 2021-06-15
 */
@RestController
@RequestMapping("//courseMaterial")
public class CourseMaterialController {

    @Autowired
    private CourseMaterialService courseMaterialService;

    @PostMapping("/addMaterial")
    public ResultVO<Object> addMaterial(@RequestBody CourseMaterial courseMaterial) {
        if (courseMaterialService.addCourseMaterial(courseMaterial)) {
            return ResultVOUtil.success(null);
        }
        return ResultVOUtil.fail();
    }

    @DeleteMapping("/deleteMaterial/{materialId}")
    public ResultVO<Object> deleteMaterial(@PathVariable("materialId") Integer materialId) {
        if (courseMaterialService.deleteCourseMaterial(materialId)) {
            return ResultVOUtil.success(null);
        }
        return ResultVOUtil.fail();
    }

    @GetMapping("/getMaterialList/{courseId}")
    public ResultVO<List<CourseMaterial>> getMaterialList(@PathVariable("courseId") Integer courseId) {
        List<CourseMaterial> courseMaterials = courseMaterialService.getCourseMaterials(courseId);
        if (courseMaterials != null) {
            return ResultVOUtil.success(courseMaterials);
        }
        return ResultVOUtil.fail();
    }
}

